<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改页面')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-page-edit" th:object="${page}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">页面名称：</label>
                <div class="col-sm-8">
                    <input name="pageName" th:field="*{pageName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">页面描述：</label>
                <div class="col-sm-8">
                    <input name="pageDescription" th:field="*{pageDescription}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">页面接口：</label>
                <div class="col-sm-8">
                    <select name="interfaceId" id="interfaceId" class="form-control selectpicker" multiple data-live-search="true" title="请选择">
                        <option th:each="interfaceInfo : ${interfaceInfoList}" th:text="${interfaceInfo.interfaceName}" th:value="${interfaceInfo.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否模块聚合页：</label>
                <div class="col-sm-8">
                    <select name="isModuleAggregation" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{isModuleAggregation}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否风险点：</label>
                <div class="col-sm-8">
                    <select name="isRask" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{isRask}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">终端类型：</label>
                <div class="col-sm-8">
                    <select name="terminalType" class="form-control m-b" th:with="type=${@dict.getType('terminalType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{terminalType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">分类名称：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="categoryId" name="categoryId" type="hidden" th:value="${category.id}"/>
                        <input class="form-control" type="text" onclick="selectCategoryTree()" id="categoryName" th:value="${category.categoryName}" readonly="true" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="sortNum" th:field="*{sortNum}" class="form-control" type="number" required>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">父页面：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="input-group">-->
<!--                        <input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />-->
<!--                        <input class="form-control" type="text" onclick="selectPageTree()" id="treeName" readonly="true" th:field="*{parentName}">-->
<!--                        <span class="input-group-addon"><i class="fa fa-search"></i></span>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">产品版本</label>
                <div class="col-sm-8">
                    <select name="productId" id="productId" class="form-control noselect2 selectpicker" style="width:300px !important;" multiple data-live-search="true" title="请选择">
                        <option th:each="info : ${productList}" th:text="${info.productName}" th:value="${info.id}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "page/page";
        $("#form-page-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $('#form-page-edit').serializeArray();
                var interfaceIds = $('#interfaceId').selectpicker('val');
                data.push({"name": "interfaceIds", "value": interfaceIds});
                var productIds = $('#productId').selectpicker('val');
                data.push({"name": "productIds", "value": productIds});
                $.operate.save(prefix + "/edit", data);
            }
        }

        var prefix2 = ctx + "category/category"
        /*分类体系-新增-选择父分类体系树*/
        function selectCategoryTree() {
            var options = {
                title: '分类体系选择',
                width: "380",
                url: prefix2 + "/selectCategoryTree2/0/2",
                callBack: doSubmit2
            };
            $.modal.openOptions(options);
        }

        function doSubmit2(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#categoryId").val(body.find('#treeId').val());
            $("#categoryName").val(body.find('#treeName').val());
            layer.close(index);
        }

        /*页面-编辑-选择父页面树*/
        function selectPageTree() {
            var options = {
                title: '页面选择',
                width: "380",
                url: prefix + "/selectPageTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }

        var interfaceIds = [[${interfaceIds}]];
        var productIds = [[${productIds}]];
        $(function () {
            // $('#tableId').select2({
            //     placeholder: "请选择表",
            //     allowClear: true
            // });
            $('#interfaceId').selectpicker('val', interfaceIds);
            $('#productId').selectpicker('val', productIds);
        });
    </script>
</body>
</html>